﻿using System.Collections.Generic;
using System.Linq;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoL.EntityLib.StatusEffects.Enemy;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;
using ProbeMod.StatusEffects;

namespace ProbeMod.Cards
{
    public sealed class ProbeEmpowerMeDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            CardConfig config = GetCardDefaultConfig();

            config.Rarity = Rarity.Uncommon;
            config.Type = CardType.Ability;
            config.TargetType = TargetType.Nobody;

            config.Colors = new List<ManaColor>() { ManaColor.Red };
            config.Cost = new ManaGroup() { Red = 1, Any = 1 };

            config.Value1 = 2;
            config.Value2 = 1;

            config.Index = CardIndexGenerator.GetUniqueIndex(config);
            return config;
        }
    }

    /// <summary>
    /// glhf
    /// 直到战斗结束：若你没有受到伤害，获得15金；若没有使用攻击牌，随机永久升级牌库一张牌；若没有获得过护盾或格挡，获得5点最大生命值。无法叠加
    /// </summary>
    [EntityLogic(typeof(ProbeEmpowerMeDef))]
    public sealed class ProbeEmpowerMe : ProbeCard
    {
        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            var drawCardToExile = Battle.DrawZone.Where
                (
                    c => IsUpgraded ?
                        c.CardType == CardType.Attack || c.CardType == CardType.Status || c.CardType == CardType.Misfortune:
                        c.CardType == CardType.Attack
                ).ToList();

            var discardCardToExile = Battle.DiscardZone.Where
            (
                c => IsUpgraded ?
                    c.CardType == CardType.Attack || c.CardType == CardType.Status || c.CardType == CardType.Misfortune :
                    c.CardType == CardType.Attack
            ).ToList();

            var count = drawCardToExile.Count + discardCardToExile.Count;

            yield return new ExileManyCardAction(drawCardToExile);
            yield return new ExileManyCardAction(discardCardToExile);

            yield return HealAction(count * Value1);
            yield return BuffAction<TempFirepower>(count * Value2);
        }
    }
}
